package com.atguigu.kylin;

import java.sql.*;

public class KylinJDBCTest {
    public static void main(String[] args) throws SQLException {
        String sql = "select\n" +
                "     DIM_BASE_PROVINCE.ID ,DIM_BASE_PROVINCE.PROVINCE_NAME ,DIM_USER_INFO_VIEW.NAME ,DIM_USER_INFO_VIEW.GENDER ,\n" +
                "     sum(DWD_ORDER_INFO.ORIGINAL_AMOUNT ) sum_original_amount \n" +
                "from DWD_ORDER_INFO \n" +
                "left join DIM_USER_INFO_VIEW \n" +
                "on DWD_ORDER_INFO.USER_ID =DIM_USER_INFO_VIEW.ID \n" +
                "left join DIM_BASE_PROVINCE \n" +
                "on DIM_BASE_PROVINCE.ID =DWD_ORDER_INFO.PROVINCE_ID \n" +
                "group by DIM_BASE_PROVINCE.ID ,DIM_BASE_PROVINCE.PROVINCE_NAME ,DIM_USER_INFO_VIEW.NAME ,DIM_USER_INFO_VIEW.GENDER ";
        Connection connection = DriverManager.getConnection("jdbc:kylin://hadoop102:7070/gmall", "ADMIN", "KYLIN");
        PreparedStatement ps = connection.prepareStatement(sql);
        ResultSet resultSet = ps.executeQuery();
        while (resultSet.next()) {
            String s = resultSet.getString("ID") + "," + resultSet.getString("PROVINCE_NAME") + "," +
                    resultSet.getString("NAME") + "," + resultSet.getString("GENDER")
                    + "," + resultSet.getBigDecimal("sum_original_amount");
            System.out.println(s);
        }
        ps.close();
        connection.close();

    }
}
